package futian
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	public class XiangkuangSelect extends Sprite
	{
		public function XiangkuangSelect()
		{

			if(stage){
				//stage.addEventListener(KeyboardEvent.KEY_UP, show);
			}else{
				addEventListener(Event.ADDED_TO_STAGE,init);
			}
		}

		private function init(e:Event):void
		{
			//stage.addEventListener(KeyboardEvent.KEY_UP, show);
			//stage.addEventListener(KeyboardEvent.KEY_DOWN, show);
			stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseMoves);

			addCircle(Datas.xiangkuangArr);
		}
		private var circle:Circle;
		private  function addCircle(pictureArr:Array):void
		{
			if (circle)
			{
				removeChild(circle);
				ViewSet.removes(circle);
				circle = null;
			}
			//if(pictureArr!=Datas.allAssetsArr)
			{
				circle = new Circle(pictureArr);
				addChild(circle);
				circle.addEventListener(Event.COMPLETE,selected);
			}
		}
		private function selected(e:Event=null):void
		{
			var obj:Object = circle.curPicture.obj;
			var asset:Object = Datas.xiangkuangArr[obj.index];
			logs.adds(asset.icon);
		}


		private var stageMouseX:int;
		private var stageMouseY:int;
		private function mouseMoves(e:MouseEvent):void
		{
			if(circle==null)
				return;
			//stopScreenSaver();
			switch(e.type)
			{
				case MouseEvent.MOUSE_DOWN:
					stageMouseX = stage.mouseX;
					stageMouseY = stage.mouseY;
					//logs.adds(stageMouseX,stageMouseY);
					stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoves);
					stage.addEventListener(MouseEvent.MOUSE_UP,mouseMoves);
					break;
				case MouseEvent.MOUSE_MOVE:
					//logs.adds(stage.mouseX,stage.mouseY);
					if(stage.mouseY>stage.stageHeight/3 && stageMouseY>stage.stageHeight/3)
					{
						if(stage.mouseX-stageMouseX>stage.stageWidth/10){
							stageMouseY = 0;
							stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoves);
							circle.dispatchEvent(new Event(Circle.RIGHT));
						}else if(stageMouseX - stage.mouseX >stage.stageWidth/10){
							stageMouseY = 0;
							stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoves);
							circle.dispatchEvent(new Event(Circle.LEFT));
						}
					}
					break;
				case MouseEvent.MOUSE_UP:
					stageMouseY = 0;
					stage.removeEventListener(MouseEvent.MOUSE_UP,mouseMoves);
					stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoves);
					break;

			}
		}
	}
}
